package com.easyaop.test.core.buddy;

import net.bytebuddy.asm.Advice;

import java.lang.reflect.Method;
import java.util.Arrays;

public class LoggerAdvisor {
    @Advice.OnMethodEnter
    public static long onMethodEnter(@Advice.Origin Method method
            , @Advice.AllArguments Object[] arguments) {
        long l = System.currentTimeMillis();
        System.out.println("args " + Arrays.toString(arguments));
        return l;
    }

    @Advice.OnMethodExit
    public static void onMethodExit(
            @Advice.Origin Method method
            , @Advice.This Object thisObject
            , @Advice.AllArguments Object[] arguments
            , @Advice.Return Object ret
            , @Advice.Enter long startTime
    ) {
        System.out.println("ret:"
                        + ret
                        + " , startTime: " + startTime
                        + " , this: " + thisObject
                        + " , args: " + arguments
//                +", throwable: "+throwable
        );
    }
}
